use rand::Rng; // trait,
use std::cmp::Ordering;
use std::io; // prelude,

fn main() {
    println!("guess number!");
    let secret_number = rand::thread_rng().gen_range(1, 101);
    println!("random number is {}", secret_number);

    loop {
        println!("input number! random_num is {}", secret_number);
        let mut guess = String::new();

        io::stdin()
            .read_line(&mut guess)
            .expect("can not read line");

        // io::stdin().read_line(&mut guess) -> io::Result<usize>,
        // io::Result 是一个 枚举类型, OK 、 Err,
        //

        // shadow,
        let guess: u32 = match guess.trim().parse() {
            Ok(num) => num,
            Err(_) => continue,
        };

        println!("number {}", guess);
        match guess.cmp(&secret_number) {
            Ordering::Less => println!("Too small!"),
            Ordering::Greater => println!("Too big"),
            Ordering::Equal => {
                println!("Equal, Exit");
                break;
            }
        }
    }
}
